
PLUG.Platform = PLUG_PLATFORM_SHARED

PLUG.ClassName = "sh_extrapunish"
PLUG.PrintName = "Extra Punishments"
PLUG.Author = "thomasfn"

function PLUG:BuildPlayerActionList( id )
	if (id == "PUNISH") then
		return {
			{ "rocket", "Rocket", "punish" },
			{ "freeze", "Freeze", "punish" },
			{ "blind", "Blind", "punish" },
			{ "strip", "Strip Weapons", "punish" }
		}
	end
end

function PLUG:RunPlayerOperation( op, ply, info )
	if ((!ply) || (!ply:IsValid())) then return end
	if (op == "rocket") then
		plugs.Call( "DoPlayerAction", ply, "rocket" )
	end
	if (op == "strip") then
		plugs.Call( "DoPlayerAction", ply, "strip" )
	end
	if (op == "freeze") then
		plugs.Call( "OpenOpInfoMenu", { { true, "Enable" }, { false, "Disable" } }, "dofreeze", ply )
	end
	if (op == "dofreeze") then
		local a = "freeze"
		if (!info) then a = "unfreeze" end
		plugs.Call( "DoPlayerAction", ply, a )
	end
	if (op == "blind") then
		plugs.Call( "OpenOpInfoMenu", { { true, "Enable" }, { false, "Disable" } }, "doblind", ply )
	end
	if (op == "doblind") then
		local a = "blind"
		if (!info) then a = "unblind" end
		plugs.Call( "DoPlayerAction", ply, a )
	end	
end

function PLUG:DoConCommand( ply, com, args )
	if (com == "blind") then
		if (!ply:HasPriv( "punish" )) then return self:Err( ply, "You do not have enough privileges to do that!" ) end
		local target = player.GetByGID( tonumber( args[1] or "0" ) )
		if ((!target) || (!target:IsValid())) then return end
		if (!ply:CanDoActionOn( target )) then
			ply:PrintMessage( HUD_PRINTTALK, "You can't do that to that player!" )
			return true
		end
		ply:Log( "punish", "Blinded " .. target:SteamID() )
		ply:PrintMessage( HUD_PRINTTALK, "Blinded " .. target:Nick() .. "!" )
		plugs.Call( "SendChatNotice", ply:Nick() .. " blinded " .. target:Nick() .. "!", true )
		umsg.Start( "gmanage", target )
		umsg.String( "blind" )
		umsg.End()
		return true
	end
	if (com == "unblind") then
		if (!ply:HasPriv( "punish" )) then return self:Err( ply, "You do not have enough privileges to do that!" ) end
		local target = player.GetByGID( tonumber( args[1] or "0" ) )
		if ((!target) || (!target:IsValid())) then return end
		if (!ply:CanDoActionOn( target )) then
			ply:PrintMessage( HUD_PRINTTALK, "You can't do that to that player!" )
			return true
		end
		ply:Log( "punish", "Unblinded " .. target:SteamID() )
		ply:PrintMessage( HUD_PRINTTALK, "Unblinded " .. target:Nick() .. "!" )
		plugs.Call( "SendChatNotice", ply:Nick() .. " unblinded " .. target:Nick() .. "!", true )
		umsg.Start( "gmanage", target )
		umsg.String( "unblind" )
		umsg.End()
		return true
	end
	if (com == "freeze") then
		if (!ply:HasPriv( "punish" )) then return self:Err( ply, "You do not have enough privileges to do that!" ) end
		local target = player.GetByGID( tonumber( args[1] or "0" ) )
		if ((!target) || (!target:IsValid())) then return end
		if (!ply:CanDoActionOn( target )) then
			ply:PrintMessage( HUD_PRINTTALK, "You can't do that to that player!" )
			return true
		end
		ply:Log( "punish", "Froze " .. target:SteamID() )
		ply:PrintMessage( HUD_PRINTTALK, "Froze " .. target:Nick() .. "!" )
		plugs.Call( "SendChatNotice", ply:Nick() .. " froze " .. target:Nick() .. "!", true )
		target:Freeze( true )
		return true
	end
	if (com == "unfreeze") then
		if (!ply:HasPriv( "punish" )) then return self:Err( ply, "You do not have enough privileges to do that!" ) end
		local target = player.GetByGID( tonumber( args[1] or "0" ) )
		if ((!target) || (!target:IsValid())) then return end
		if (!ply:CanDoActionOn( target )) then
			ply:PrintMessage( HUD_PRINTTALK, "You can't do that to that player!" )
			return true
		end
		ply:Log( "punish", "Unfroze " .. target:SteamID() )
		ply:PrintMessage( HUD_PRINTTALK, "Unfroze " .. target:Nick() .. "!" )
		plugs.Call( "SendChatNotice", ply:Nick() .. " unfroze " .. target:Nick() .. "!", true )
		target:Freeze( false )
		return true
	end
	if (com == "rocket") then
		if (!ply:HasPriv( "punish" )) then return self:Err( ply, "You do not have enough privileges to do that!" ) end
		local target = player.GetByGID( tonumber( args[1] or "0" ) )
		if ((!target) || (!target:IsValid())) then return end
		if (!ply:CanDoActionOn( target )) then
			ply:PrintMessage( HUD_PRINTTALK, "You can't do that to that player!" )
			return true
		end
		ply:Log( "punish", "Rocketed " .. target:SteamID() )
		ply:PrintMessage( HUD_PRINTTALK, "Rocketed " .. target:Nick() .. "!" )
		plugs.Call( "SendChatNotice", ply:Nick() .. " rocketed " .. target:Nick() .. "!", true )
		target:SetVelocity( Vector( 0, 0, 2500 ) )
		timer.Simple( 4, function()
			// target:EmitSound( "weapons/explode5.wav" )
			local e = EffectData()
			e:SetStart( target:GetPos() + Vector( 0, 0, 32 ) )
			e:SetOrigin( e:GetStart() )
			e:SetScale( 1 )
			util.Effect( "Explosion", e )
			target:Kill()
		end )
		return true
	end
	if (com == "strip") then
		if (!ply:HasPriv( "punish" )) then return self:Err( ply, "You do not have enough privileges to do that!" ) end
		local target = player.GetByGID( tonumber( args[1] or "0" ) )
		if ((!target) || (!target:IsValid())) then return end
		if (!ply:CanDoActionOn( target )) then
			ply:PrintMessage( HUD_PRINTTALK, "You can't do that to that player!" )
			return true
		end
		ply:Log( "punish", "Stripped " .. target:SteamID() )
		ply:PrintMessage( HUD_PRINTTALK, "Stripped " .. target:Nick() .. "!" )
		plugs.Call( "SendChatNotice", ply:Nick() .. " stripped weapons and ammo of " .. target:Nick() .. "!", true )
		target:StripWeapons()
		target:StripAmmo()
		return true
	end
end

function PLUG:Err( ply, message )
	ply:PrintMessage( HUD_PRINTTALK, message )
	return true
end

if (CLIENT) then
	local black = Color( 0, 0, 0 )
	function PLUG:UserMessage( tag, um )
		if (tag == "blind") then
			self.BLINDER = vgui.Create( "DPanel" )
			self.BLINDER:SetPos( 0, 0 )
			self.BLINDER:SetSize( ScrW(), ScrH() )
			function self.BLINDER:Paint()
				surface.SetDrawColor( black )
				surface.DrawRect( 0, 0, self:GetWide(), self:GetTall() )
			end
			return true
		end
		if (tag == "unblind") then
			if (self.BLINDER) then
				self.BLINDER:Remove()
				self.BLINDER = nil
			end
			return true
		end	
	end
end